﻿using phones.Repository;
using phones.Model;
using phones.ViewModel.TreeViewModel;

namespace phones.ViewModel
{
    public class OrganisationNodeTreeItemViewModel: TreeViewItemBaseViewModel
    {
        private Organisation _organisation;

        public Organisation Model
        { get { return _organisation; } }

        public OrganisationNodeTreeItemViewModel(ServiceNodeTreeItemViewModel parent, Organisation organisation)
            : base(parent, true)
        {
            _organisation = organisation;
        }

        protected override void LoadChildren()
        {
            Children.Clear();

            var db = new DepartmentsRepository();
            var list = db.GetList(
                    (Parent as ServiceNodeTreeItemViewModel).Model,
                    _organisation
                );

            foreach (var item in list)
            {
                 Children.Add(new DepartnemtNodeTreeItemViewModel(this, item));
            }
        }
    }
}
